package service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import pojo.User;
import service.UserService;

public class UserServiceImpl implements UserService{
	
	private static List<User> users = new ArrayList<User>();
	
	public User addUser(User user){
		synchronized (users) {
			user.setId(UUID.randomUUID().toString());
			users.add(user);
		}
		return user;
	}
	
	public String deleteUser(String id) {
		synchronized (users) {
			for(int i =0 ; i < users.size(); i++){
				if(users.get(i).getId().equals(id)){
					users.remove(i);
				}
			}
		}
		return "success";
	}
	
	public User updateUser(User user) {
		deleteUser(user.getId());
		synchronized (users) {
			users.add(user);
		}
		return user;
	}
	
	public List<User> queryAllUser() {
		return users;
	}
}
